home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 008 / 68kgraph.arc / CREEP.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-13  |  3.4 KB  |  97 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * CREEP - Does a "spreading dot" trick
  13. #bit.h
  14.  
  15.     xdef    creep
  16.     xref    g_pix,image
  17.  
  18. *****************************************************************
  19. * CREEP - Fills all "white" space adjacent to pixel (D0.W,D1.W)
  20. creep:
  21.     movem.w    d0-d4,-(a7)
  22.     move.w    d0,d2        * save pixel X
  23.     move.w    d1,d3        * save pixel Y
  24. lp1_cp:
  25.     bsr    tstpix        * check this pixel
  26.     bne    sk1_cp        * we're done if this one set
  27.     bsr    g_pix        * set this pixel
  28.     subq.w    #1,d0        * move left one pixel
  29.     bra    lp1_cp        * do it 'til we boink
  30. sk1_cp:
  31.     addq.w    #1,d0        * adjust right end X position
  32.     exg    d0,d2        * save leftmost, get original
  33.     addq.w    #1,d0        * move left of original
  34. lp2_cp:
  35.     bsr    tstpix        * check this pixel
  36.     bne    sk2_cp        * we're done if this one set
  37.     bsr    g_pix        * set this pixel
  38.     addq.w    #1,d0        * move right one pixel
  39.     bra    lp2_cp        * keep on to the right end
  40. sk2_cp:
  41.     subq.w    #1,d0        * adjust left end X position
  42.     move.w    d0,d4        * save left end X position
  43.  
  44.     move.w    d2,d0        * get left end X position
  45.     addq.w    #1,d1        * move down to next row
  46.     bsr    run        * check the run for adjacent pixs
  47.  
  48.     move.w    d2,d0        * get right end X limit
  49.     move.w    d3,d1        * get original Y
  50.     subq.w    #1,d1        * move up one row
  51.     bsr    run        * check for adjacent white pixels
  52.  
  53.     movem.w    (a7)+,d0-d4
  54.     rts
  55. *****************************************************************
  56. run:
  57.     bsr    tstpix        * check this pixel
  58.     bne    sk4_cp        * set, no need to worry
  59.     bsr    creep        * set the new line
  60. sk4_cp:
  61.     addq.w    #1,d0        * move right one pixel
  62.     cmp.w    d0,d4        * test against right limit
  63.     bge    run        * loop if more to check
  64.     rts
  65. *****************************************************************
  66. * TSTPIX - tests the pixel where D0.W = X and D1.W = Y
  67. *          returns zero flag TRUE if pixel not set
  68. tstpix:
  69.     movem.l    d0/d1/a0,-(a7)    * save caller's registers
  70. ******* See if X and Y are valid addresses *********************
  71.     tst.w    d0        * look for off left edge
  72.     bmi    sk1_pix        * error out if so
  73.     tst.w    d1        * look for off top
  74.     bmi    sk1_pix        * error out if so
  75.     cmp.w    #hor_b,d0    * look for off right edge
  76.     bge    sk1_pix        * error out if so
  77.     cmp.w    #vert,d1    * look for off bottom
  78.     bge    sk1_pix     * error out if so
  79. ******* pixel (X,Y) is valid; check value of pixel **************
  80.     move.l    #image,a0    * get base of image area
  81.     mulu    #(hor_w*2),d1    * get vertical offset to line
  82.     add.l    d1,a0        * and add to base address
  83.     move.w    d0,d1        * save X for later
  84.     lsr.w    #3,d0        * get number of bytes to pixel 
  85.     add.w    d0,a0        * add to pointer
  86.     and.w    #$0007,d1    * strip all but bit number
  87.     btst    d1,(a0)        * test the bit
  88.     bra    sk2_pix        * and exit
  89. sk1_pix:
  90.     andi    #$FB,ccr    * errors always show set pixel
  91. sk2_pix:
  92.     movem.l    (a7)+,d0/d1/a0    * restore caller's registers
  93.     rts
  94. *****************************************************************
  95.     end
  96.